package com.gitee.swsk33.providerdemo.api;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Enumeration;

@RestController
@RequestMapping("/api/receiver")
public class ReceiverAPI {

	@GetMapping("/hello")
	public String get() {
		return "请求成功转发到此！";
	}

	@GetMapping("/get-header")
	public String getHeader(HttpServletRequest request) {
		Enumeration<String> headers = request.getHeaderNames();
		while (headers.hasMoreElements()) {
			String name = headers.nextElement();
			System.out.println("键：" + name + " 值：" + request.getHeader(name));
		}
		return "已接收并解析请求头！";
	}

	@GetMapping("/get-param")
	public String getParam(@RequestParam("my-param") String param) {
		System.out.println(param);
		return "已接收并解析请求参数！";
	}

	@GetMapping("/test-response")
	public String response() {
		return "已接收并返回响应！";
	}

}